unit MaskedPassword;

interface

const
 DefaultMask = '*';

function MaskPassword(Password: String; Mask: Char = DefaultMask): String;
procedure UpdateMaskedPassword(UpdatedMasked: String; var Password: String; Mask: Char = DefaultMask);

implementation

function MaskPassword(Password: String; Mask: Char = DefaultMask): String;
 var
  i: Integer;
begin
 Result:='';
 for i:=1 to Length(Password) do
   Result:=Result+Mask;
end;

procedure UpdateMaskedPassword(UpdatedMasked: String; var Password: String; Mask: Char = DefaultMask);
 var
  i: Integer;
begin
 for i:=1 to Length(UpdatedMasked) do
  begin
   if UpdatedMasked[i]<>Mask then
    begin
     if i>Length(Password) then
       Password:=Password+UpdatedMasked[i]
     else
       Password[i]:=UpdatedMasked[i];
    end;
   if Length(Password)>Length(UpdatedMasked) then
     Password:=Copy(Password, 1, Length(UpdatedMasked));
  end;
end;

end.
 